package cn.schoolwow.util.test.module.check.instanceList.flow;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.util.domain.check.instanceList.CheckInstanceList;
import cn.schoolwow.util.domain.query.instanceList.QueryInstanceList;
import cn.schoolwow.util.test.module.check.common.domain.AddProject;

import java.util.Arrays;
import java.util.List;

public class CheckAddProjectAssignJobProcessFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        AddProject addProject = (AddProject) flowContext.checkData("addProject");

        List<String> timeNodeNameList = QueryInstanceList.newQuery(addProject.timeNodeList)
                .execute()
                .getSingleFieldValueList("name");
        CheckInstanceList.newCheck(addProject.assignJobList)
                .notNullCheck("analyzeWorkId", "分析工作id")
                .notNullCheck("analyzeWorkName", "分析工作名称")
                .notNullCheck("userId", "分配用户")
                .notNullCheck("username", "分配用户名")
                .notEmptyCheck("analyzeTimeNodeNameList", "分析节点列表")
                .inValueCheck("analyzeTimeNodeNameList", timeNodeNameList, "分析节点列表")
                .inValueCheck("analyzeTimeNodeNameList", timeNodeNameList, "分析节点列表")
                .notRepeatCheck(Arrays.asList("analyzeWorkId", "analyzeWorkName"), "分析工作名称")
                .idFieldCheck("analyzeWorkId", "分析工作id")
                .idFieldCheck("userId", "用户id");

        CheckInstanceList.newCheck(addProject.timeNodeList)
                .containValueCheck("name", "时间节点4","新增的时间节点")
                .notRepeatCheck("name", "时间节点名称");
    }

    @Override
    public String name() {
        return "检查新增项目实例-分析工作列表";
    }
}
